﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LightCAD.Core
{

    public interface IModelObject 
    {
        string Uuid { get; set; }
        string Name { get; set; }
        Transform3d Transform { get; }
    }
    public  interface IModelSpace
    {
        string Uuid { get; set; }
        string Name { get; }
        public ListEx<IModelArea> Areas { get;}
        IModelSpace AddAreas(params IModelArea[] areas);
        
    }
    public class ModelSpace : IModelSpace
    {
        public string Uuid { get ; set  ; }

        public string Name { get; set; }

        public ListEx<IModelArea> Areas { get; }=new ListEx<IModelArea>();

        public IModelSpace AddAreas(params IModelArea[] areas)
        {
            this.Areas.AddRange(areas);
            return this;
        }
    }
    public interface IModelArea : IModelObject
    {
        ListEx<IModelSite> Sites { get; }
        IModelArea AddSites(params IModelSite[] sites);
    }
    public class ModelArea : IModelArea
    {
        public ListEx<IModelSite> Sites { get; }=new ListEx<IModelSite>();

        public string Uuid { get ; set ; }
        public string Name { get; set; }

        public Transform3d Transform { get; }=new Transform3d   ();

        public IModelArea AddSites(params IModelSite[] sites)
        {
           this.Sites.AddRange(sites);
            return this;
        }
    }
    public interface IModelSite : IModelObject
    {
        ListEx<IModelGroup> Groups { get; }
        IModelSite AddGroups(params IModelGroup[] groups);
      
    }
    public class ModelSite : IModelSite
    {
        public ListEx<IModelGroup> Groups { get; } = new ListEx<IModelGroup>();

        public string Uuid { get; set; }
        public string Name { get; set; }

        public Transform3d Transform { get; } = new Transform3d();

        public IModelSite AddGroups(params IModelGroup[] groups)
        {
            this.Groups.AddRange(groups);
            return this;
        }
    }
    public interface IModelGroup : IModelObject
    {
        public ListEx<IModelNode> Nodes { get; }
        public ListEx<IModelGroup> Groups { get; }
        IModelGroup AddGroups(params IModelGroup[] groups);
        IModelGroup RemoveGroups(params IModelGroup[] groups);
        IModelGroup ClearGroups();
        IModelGroup AddNodes(params IModelNode[] nodes);
        IModelGroup RemoveNodes(params IModelNode[] nodes);
        IModelGroup ClearNodes();
    }
    public interface IModelNode : IModelObject
    {
        IComponentInstance Component { get; set; }
    }
    public class ModelGroup : IModelGroup
    {
        public ListEx<IModelNode> Nodes { get; } = new ListEx<IModelNode>();

        public ListEx<IModelGroup> Groups { get; } = new ListEx<IModelGroup>();
        public string Uuid { get; set; }

        public Transform3d Transform { get; } = new Transform3d();

        public string Name { get; set; }

        public IModelGroup AddGroups(params IModelGroup[] groups)
        {
            this.Groups.AddRange(groups);
            return this;
        }

        public IModelGroup AddNodes(params IModelNode[] nodes)
        {
            this.Nodes.AddRange(nodes);
            return this;
        }

        public IModelGroup RemoveGroups(params IModelGroup[] groups)
        {
            for (int i = 0; i < groups.Length; i++)
            {
                this.Groups.Remove(groups[i]);
            }
            return this;
        }

        public IModelGroup ClearGroups()
        {
            this.Groups.Clear();
            return this;
        }

        public IModelGroup RemoveNodes(params IModelNode[] nodes)
        {
            for (int i = 0; i < nodes.Length; i++)
            {
                this.Nodes.Remove(nodes[i]);
            }
            return this;
        }

        public IModelGroup ClearNodes()
        {
            this.Nodes.Clear();
            return this;
        }
    }
    public class ModelNode : IModelNode
    {
        public string Uuid { get; set ; }
        public string Name { get; set; }
        public Transform3d Transform { get; }=new Transform3d();
        public IComponentInstance Component { get; set; }
    }
}
